package com.yeswater.multithread.chapter2.test2_1.test10;

/**
 * author : yeswater
 * date : 2023/10/20
 */

public class Run {

    /*
     * 重写的方法也要加 synchronized 才能同步
     * int sub 下一步 sleep begin threadName=A time=1697765060796
     * int sub 下一步 sleep begin threadName=B time=1697765060796
     * int sub 下一步 sleep   end threadName=B time=1697765065803
     * int sub 下一步 sleep   end threadName=A time=1697765065803
     */
    public static void main(String[] args) {
        Sub subRef = new Sub();

        MyThread a = new MyThread(subRef);
        a.setName("A");
        a.start();
        MyThread b = new MyThread(subRef);
        b.setName("B");
        b.start();


    }

    public static class MyThread extends Thread {
        private Sub sub;

        public MyThread(Sub sub) {
            this.sub = sub;
        }

        @Override
        public void run() {
            sub.serviceMethod();
        }
    }

}
